package com.orange.modules.dao.expert;

import java.sql.SQLException;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.orange.dbhelp.DbHelper;
import com.orange.dbhelp.page.Page;
import com.orange.modules.entity.expert.AuthExpertAdvice;
import com.orange.modules.entity.expert.AuthExpertise;

@Repository
public class AuthExpertiseRepository {

	@Resource(name = "dbHelper")
	private DbHelper dbHelper;
	
	@Autowired
	private AuthExpertiseDao authExpertiseDao;
	
	/**
	 * 保存专家评价
	 */
	public void saveAuthExpertAdvice(AuthExpertise a){
		authExpertiseDao.save(a);
	}
	
	/**
	 * 查询专家评价
	 * @throws SQLException 
	 */
	public List<AuthExpertise> queryAuthExpertise(String groupId) throws SQLException{
		String sql = "select a.p_id as pid,a.s_group_id as groupId,a.s_expert_id as expertId,a.s_working_attitude as workingAttitude,a.s_professional_level as professionalLevel," +
				" a.s_evaluatio_ability as evaluatioAbility,a.s_probityself_discipline as probityselfDiscipline, a.s_team_spirit as teamSpirit, a.s_create_time as createTime," +
				" b.s_expert_name as expertName, d.s_name as groupName" +
				" from t_auth_expert as b LEFT join t_auth_expertise as a on a.s_expert_id = b.p_id left join t_auth_export_group_map as c on b.p_id = c.s_export_id" +
				" LEFT JOIN t_auth_group as d on c.s_group_id = d.p_id where c.s_group_id = ?";
		return dbHelper.getBeanList(sql, AuthExpertise.class, groupId);
		
	}
	
	/**
	 * 分页查询专家评价
	 * @throws SQLException 
	 * @throws NumberFormatException 
	 */
	public Page<AuthExpertise> queryAuthExpertiseByPage(Map<String, String> map) throws SQLException{
		StringBuilder sql = new StringBuilder("SELECT DISTINCT TOP 1000 a.s_group_id as groupId,c.s_name as groupName from t_auth_expertise as a left join t_auth_group as c on a.s_group_id = c.p_id where 1=1");
		Page<AuthExpertise> aea = dbHelper.getPage(sql.toString(),AuthExpertise.class, Integer.valueOf(map.get("pageNumber")),
				Integer.valueOf(map.get("pageSize")), new Object[] {});
		return aea;
		
	}
}
